<template>
  <div>
    <el-radio-group v-model="radio" @change="handleCheck">
      <el-radio v-for="(item, index) in list" :key="index" :label="item.value">
        {{ item.name }}
      </el-radio>
    </el-radio-group>
  </div>
</template>

<script>
export default {
  name: 'RadioGroup',
  props: {
    list: {
      type: Array,
      default: () => {}
    },
    value: {
      type: String,
      default: ''
    }
  },
  model: {
    prop: 'value',
    event: 'check-value'
  },
  data() {
    return {
      radio: ''
    }
  },
  watch: {
    value() {
      this.setValue()
    }
  },
  created() {
    this.setValue()
  },
  methods: {
    setValue() {
      if (this.value) {
        this.radio = this.value
      }
    },
    handleCheck() {
      this.$emit('check-value', this.radio)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
